package cn.dengta.webapp.trade.service;

import javax.annotation.Resource;

import cn.dengta.context.model.RedisKey;
import cn.dengta.webapp.trade.config.IpBlacklistProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

/**
 * IP黑名单服务
 *
 * @author zw
 * @since 2024/07/04
 */
@Slf4j
@Service
public class IpBlacklistService {

	@Resource
	IpBlacklistProperties ipBlacklistProperties;
	@Resource
	StringRedisTemplate stringRedisTemplate;

	public boolean isBlacklistUser(Long userId) {
		// 如果没有启用，直接返回false
/*		if (!ipBlacklistProperties.isEnabled()) {
			return false;
		}*/
		// 如果没有用户不在黑名单城市，直接返回false
		return Boolean.TRUE.equals(stringRedisTemplate.opsForSet().isMember(RedisKey.IP_BLACK_LIST, userId.toString()));
	}

}
